import uri from './uri/index'
import { request, get, post, put, del } from '@/xhr/service'

const files = require.context('./modules', true, /\.js$/)
const apiGenerators = files.keys().map(key => files(key).default)

const api = {}
apiGenerators.forEach(generator => {
  const apiInstance = generator({
    request,
    get,
    post,
    put,
    del,
    uri
  })
  for (const apiName in apiInstance) {
    if (apiInstance.hasOwnProperty(apiName)) {
      api[apiName] = apiInstance[apiName]
    }
  }
})

export {
  api,
  uri
}

export default {
  api,
  uri
}
